package com.bjpowernode.service;

import com.bjpowernode.service.impl.SomeServiceImpl;
import com.bjpowernode.handler.MyInvocationHandler;

import java.lang.reflect.Proxy;

public class MyApp {
    public static void main(String[] args) {
       /* SomeService someService=new SomeServiceImpl();
        someService.doSome();
        System.out.println("=================");
        someService.doOthers();*/

       //使用jdk的Proxy创建代理对象
        //创建目标类对象
        SomeService target=new SomeServiceImpl();

        //创建InvocationHandler对象
        MyInvocationHandler invocationHandler=new MyInvocationHandler(target);

        //使用Proxy创建代理
SomeService proxy=(SomeService) Proxy.newProxyInstance(target.getClass().getClassLoader()
                ,target.getClass().getInterfaces()
                ,invocationHandler);

       //
       proxy.doSome();
       proxy.doOthers();
    }
}
